--[[
	Ikarus Unit-Frames Addon	
	released under GNU General Public License version 3 (GPLv3) 
	by McGaerty & Sl4ker
	
	contact: mcgaerty@ikarus-systems.net rom@sl4ker.de	
	download: http://rom.curse.com/downloads/rom-addons/details/ikarus-unitframes.aspx
	
	special thanks to Qwox and novayuna for inspiration and stable basics
]]




--[[   
	{"Name", "Template", "Hint","UIComponent",RequiresReloadFlag,OptionalData}
	
	-Name				String	The exact name of the property, used by the corresponding delegate
	-Template				String	The template name of the property, used for internal lookup of displayed property title, nil if equal to Name field
	-Hint			String	Tooltip text for complex properties
	-UIComponent			String	Hint what type of component to use for this property (see list below)
	-RequiresReloadFlag		Boolean	true for properties which need to reload data from files, false otherwise (might even miss)
	-OptionalData			Entry		optional data used to configurate UI component (for information see list below)
	
	
	List of components (items for optional data are in brackets, required items are marked with '*'):
	-CHECKBOX			uses a simple checkbox
	-TEXTFIELD			uses a textfield with no input verifier
	-NUMBERFIELD			uses a textfield with an input verifier accepting only numbers (MIN, MAX) 
	-SLIDER				uses a slider to traverse a certain range of number values (*MIN, *MAX, STEP_LENGTH, LEFT_LABLE, RIGHT_LABLE)
	-SLIDER	uses a slider in combination with a number field (*MIN, *MAX, STEP_LENGTH, LEFT_LABLE, RIGHT_LABLE)
	-COLORPICKER			uses a colorpicker (DEFAULT_COLOR)
	-COMBOBOX			uses a combo box as drop down menu (*OPTIONS,LOCALIZE)
	-TEXT				just displays the text given by the optional arguments in blocks
	
	Important note: 
		For all optional items you may provide functions or config links as arguments! Those functions must not take arguments
		and should at least return one value for the given option.
		If you want to provide a config link, type it in the following syntax:
		"##category.item"
		This will look in the ikarus.config.category.item field and use it as argument, if it is a function, it will be executed
		If you want to have access to a frame function, use:
		"$$frame.func"
		This will try to call the function 'func' as field of frame 'frame' and use the result as argument
		
		
	List of available config.interface values
		MAX_OFFSET_X
		MAX_OFFSET_Y
		BAR_TEXTURES
		FONTS
		MIN_FONT_SIZE
		MAX_FONT_SIZE
		ALIGNMENTS
		SIMPLE_ALIGNMENTS
		ORIENTATIONS
		NUMBER_FORMATS
		COLORIZERS#
		LANGUAGES
		PROFILES
]]


do

ikarus.config.defaults.global = {
	["GENERAL"] = {
		["VISIBLE"] = false,
		["WOW_STYLE"] = false,
		["SYSTEM_COLOR"] = false,
		["USE_GLOBAL_TEXTURE"] = false,
		["GLOBAL_TEXTURE"] = "Minimalist",
		["LANGUAGE"] = "ENEU",
		["PROFILE"] = nil,
		["FRAME"] = "Ikarus_EventFrame"
	}
};

table.insert(ikarus.config.interface, 
	{
		"global",
		
		--  General
		
		{
			"GENERAL",
			{"WOW_STYLE", nil, nil,"CHECKBOX"},
			{"SYSTEM_COLOR", nil, nil,"CHECKBOX"},
			{"USE_GLOBAL_TEXTURE", nil, nil,"CHECKBOX", true},
	        {"GLOBAL_TEXTURE", nil, nil,"COMBOBOX", true, "##interface.BAR_TEXTURES"},
	        {"DUMMY_STATE", nil, nil,"BUTTON", false}, 
	        {"LANGUAGE", nil, nil,"COMBOBOX", true, "##interface.LANGUAGES",true},
			{"PROFILE", nil, nil,"COMBOBOX", true, "##interface.PROFILES"}
		}
		
		--  Help (Later)
		
		-- {
			-- "HELP",
			-- {"IUC",nil,nil,"TEXT","IUC_ABOUT","IUC_EXAMPLE"}
		-- }
	}
);


--  ***********************************************************************
--  class handling player unit frame behavior
ikarus.delegates.GlobalDelegateClass = ikarus:NewClass(ikarus.delegates.BasicUnitDelegateClass);

function ikarus.delegates.GlobalDelegateClass:Init()
	self.unit = "global";
	self.eventList = {};
end;

function ikarus.delegates.GlobalDelegateClass:OnEvent(event, ...)  
end;

function ikarus.delegates.GlobalDelegateClass:OnScriptEvent(event, ...)
end;

function ikarus.delegates.GlobalDelegateClass:HideDefaultFrame()
end;

function ikarus.delegates.GlobalDelegateClass:ShowDefaultFrame()
end;

function ikarus.delegates.GlobalDelegateClass:UpdateAll()
end;

function ikarus.delegates.GlobalDelegateClass:SetDummy(enable)
	self.dummy = enable;
	ikarus:SetDummyState(enable);
end;


function ikarus.delegates.GlobalDelegateClass:LoadConfig()
	local profileName = self:Profile().GENERAL.PROFILE;
	if(profileName ~= ikarus:GetProfileName()) then
		ikarus:SetProfileName(profileName, true);
		ikarus.config:SaveProfile();
	end;
	ikarus:LoadLocales();
	if(ikarus.config.menu and ikarus.config.menu:IsVisible()) then
		ikarus.config.menu:HideConfigFrame()
		ikarus.config.menu:ShowConfigFrame();
	elseif(ikarus.profileManager and ikarus.profileManager:IsVisible()) then
		ikarus.profileManager:HideConfigFrame()
		ikarus.profileManager:ShowConfigFrame();
	end;
	for unit, delegate in pairs(ikarus.unitDelegates) do
		if(unit ~= self.unit) then
			delegate:LoadConfig();
		end;
	end;
end;

function ikarus.delegates.GlobalDelegateClass:LoadBoundProperties()
	for unit, delegate in pairs(ikarus.unitDelegates) do
		if(unit ~= self.unit) then
			delegate:LoadBoundProperties();
		end;
	end;
end;
--  ***********************************************************************

--  Instantiate our delegate with the 
return ikarus.delegates.GlobalDelegateClass:Create();
	
	
end;